﻿using System;
using System.Data;
using System.Collections.Generic;

namespace DMZS.BLL
{
    /// <summary>
    /// Etype
    /// </summary>
    public partial class Etype
    {
        private readonly DMZS.DAL.Etype dal = new DMZS.DAL.Etype();
        public Etype()
        {
        }

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int EtypeFID)
        {
            return dal.Exists(EtypeFID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int  Add(DMZS.Model.Etype model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(DMZS.Model.Etype model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int EtypeFID)
        {
            return dal.Delete(EtypeFID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string EtypeFIDlist )
        {
            return dal.DeleteList(EtypeFIDlist );
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DMZS.Model.Etype GetModel(int EtypeFID)
        {
            return dal.GetModel(EtypeFID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public DMZS.Model.Etype GetModelByCache(int EtypeFID)
        {
            var CacheKey = "EtypeModel-" + EtypeFID;
            var objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(EtypeFID);
                    if (objModel != null)
                    {
                        var ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch
                {
                }
            }
            return (DMZS.Model.Etype)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<DMZS.Model.Etype> GetModelList(string strWhere)
        {
            var ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<DMZS.Model.Etype> DataTableToList(DataTable dt)
        {
            var modelList = new List<DMZS.Model.Etype>();
            var rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                DMZS.Model.Etype model;
                for (var n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList(string.Empty);
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        /// <summary>
        /// 通过编号获取记录
        /// </summary>
        /// <param name="Eusercode"></param>
        /// <returns></returns>
        public DataTable GetRecordByNo(string Eusercode)
        {
            return dal.GetRecordByNo(Eusercode);
        }
        /// <summary>
        /// 通过编号获取记录条数
        /// </summary>
        public int GetRecordCountByNo(string Eusercode)
        {
            return dal.GetRecordCountByNo(Eusercode);
        }
        /// <summary>
        /// 通过编号获取记录
        /// </summary>
        /// <param name="Eusercode"></param>
        /// <returns></returns>
        public int ExistsByNo(string Eusercode)
        {
            return dal.ExistsByNo(Eusercode);
        }
    }
}

